package vn.com.horoscope.activity;

import vn.com.horoscope.R;
import vn.com.horoscope.common.ConstantClass;
import vn.com.horoscope.common.StaticClass;
import vn.com.horoscope.common.Utilities;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;

public class MainActivity extends Activity implements OnClickListener{
	ImageView img1,img2,img3,img4,img5,img6,img7,img8,img9,img10,img11,img12 ;
	public static String data = "";

	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
		setContentView(R.layout.dashboard_layout);
		new GetDataFromServiceAsyncTask(MainActivity.this).execute();
		
		init();
		
    }	

    
    public void init(){
    	img1 = (ImageView) findViewById(R.id.imgBachDuong);
    	img2 = (ImageView) findViewById(R.id.imgKimNguu);
    	img3 = (ImageView) findViewById(R.id.imgSongTu);
    	img4 = (ImageView) findViewById(R.id.imgCuGiai);
    	img5 = (ImageView) findViewById(R.id.imgSuTu);
    	img6 = (ImageView) findViewById(R.id.imgXuNu);
    	img7 = (ImageView) findViewById(R.id.imgThienBinh);
    	img8 = (ImageView) findViewById(R.id.imgBoCap);
    	img9 = (ImageView) findViewById(R.id.imgNhanMa);
    	img10 = (ImageView) findViewById(R.id.imgMaKet);
    	img11 = (ImageView) findViewById(R.id.imgBaoBinh);
    	img12 = (ImageView) findViewById(R.id.imgSongNgu);
    	
    	img1.setOnClickListener(this);
    	img2.setOnClickListener(this);
    	img3.setOnClickListener(this);
    	img4.setOnClickListener(this);
    	img5.setOnClickListener(this);
    	img6.setOnClickListener(this);
    	img7.setOnClickListener(this);
    	img8.setOnClickListener(this);
    	img9.setOnClickListener(this);
    	img10.setOnClickListener(this);
    	img11.setOnClickListener(this);
    	img12.setOnClickListener(this);
    	
    	
    }
	
	

	@Override
	public void onClick(View v) {
		switch (v.getId()){
		case R.id.imgBachDuong :
			startMenuActivity(ConstantClass.bd);
			break;
		case R.id.imgKimNguu :
			startMenuActivity(ConstantClass.kn);
			break;
		case R.id.imgSongTu :
			startMenuActivity(ConstantClass.st);
			break;
		case R.id.imgCuGiai :
			startMenuActivity(ConstantClass.cg);
			break;
		case R.id.imgSuTu :
			startMenuActivity(ConstantClass.sut);
			break;
		case R.id.imgXuNu :
			startMenuActivity(ConstantClass.xn);
			break;
		case R.id.imgThienBinh :
			startMenuActivity(ConstantClass.tb);
			break;
		case R.id.imgBoCap :
			startMenuActivity(ConstantClass.bc);
			break;
		case R.id.imgNhanMa :
			startMenuActivity(ConstantClass.nm);
			break;
		case R.id.imgMaKet :
			startMenuActivity(ConstantClass.mk);
			break;
		case R.id.imgBaoBinh :
			startMenuActivity(ConstantClass.bd);
			break;
		case R.id.imgSongNgu :
			startMenuActivity(ConstantClass.sn);
			break;
			
		}
	}
	
	
	public void startMenuActivity(int i){
		Intent intent = new Intent(MainActivity.this, DetailHoroscopeActivity.class);
		intent.putExtra(ConstantClass.horoscopeParam, i);
		startActivity(intent);
	}
	
	
	
	
	private class GetDataFromServiceAsyncTask extends AsyncTask<Void, Void, Void> {
		Context ctx;
		ProgressDialog p;
		
		GetDataFromServiceAsyncTask (Context c){
			this.ctx = c;
			 p = new ProgressDialog(ctx);
		}
		
		protected void onPreExecute()
		{			
			p = ProgressDialog.show(ctx, "title", "Waiting get data ", true);			
		}
		
		@Override
		protected Void doInBackground(Void... arg0) {
			// TODO Auto-generated method stub
			StaticClass.op = Utilities.getData();
			return null;
		}
		
		
		@Override
		protected void onPostExecute(Void result) {
			// TODO Auto-generated method stub
			p.cancel();
		     
		}
		
	}
	
}
